import request from '../utils/wxRequest';
export const baseUrl = 'https://mp.youyuegw.com';

// 获取AccessToken的登录接口
export const loginApi = async function(data) {
  const res = await request.post(`${baseUrl}/oauth2/wechat`, data);
  return res;
};

// 获取首页信息接口
export const homeApi = function() {
  return request.get(`${baseUrl}/site/index`);
};

// 获取商品详情接口
export const getShopDataApi = function(data) {
  return request.get(`${baseUrl}/shop/spu/${data.id}`);
};

// 添加商品进入购物车
export const addShopToCartApi = function(data) {
  return request.post(`${baseUrl}/shop/cart/add`, data);
};

// 从购物车批量删除商品
export const deleteShopFromCartApi = function(data) {
  return request.post(`${baseUrl}/shop/cart/delete`, data);
};

// 提交购物车商品结算
export const balanceShopApi = function(data) {
  return request.post(`${baseUrl}/shop/cart/balance`, data);
};

// 需要结算的商品查询
export const packShopApi = function() {
  return request.get(`${baseUrl}/shop/cart/pack`);
};

// 购物车列表
export const getShopCartList = function(page) {
  return request.get(`${baseUrl}/shop/cart?page=${page}`);
};

// 获取用户地址列表接口
export const getAddressList = function() {
  return request.get(`${baseUrl}/user/address`);
};

// 绑定手机号接口
export const bindMobileApi = function(data) {
  return request.post(`${baseUrl}/passport/bind-mobile`, data);
};

// 获取支付参数接口
export const orderCreateApi = function(data) {
  return request.post(`${baseUrl}/course/order/create`, data);
};

// 创建地址接口
export const createAddressApi = function(data) {
  return request.post(`${baseUrl}/user/address/create`, data);
};

// 更新地址接口
export const updateAddressApi = function(id, data) {
  return request.post(`${baseUrl}/user/address/update?id=${id}`, data);
};

// 删除地址接口
export const deleteAddressApi = function(id) {
  return request.post(`${baseUrl}/user/address/delete?id=${id}`);
};

// 创建订单接口
export const createOrderApi = function(data) {
  return request.post(`${baseUrl}/shop/order/create`, data);
};

// 创建支付接口
export const createTradeOrderApi = function(data) {
  return request.post(`${baseUrl}/trade/order/create`, data);
};

// 获取分类列表
export const getCatagoryList = function() {
  return request.get(`${baseUrl}/shop/category`);
};

// 商城栏目tab列表
export const getShopCatagoryTab = function(id) {
  return request.get(`${baseUrl}/shop/category/list?id=${id}`);
};

// 商城栏目tab下商品列表
export const getShopCategoryList = function(id, page) {
  return request.get(`${baseUrl}/shop/category/${id}?page=${page}&per-page=100`);
};

// 个人中心
export const getMemberInfo = function() {
  return request.get(`${baseUrl}/user/home`);
};

// 获取订单列表数据
export const getOrderListAPI = function(page, type) {
  return request.get(`${baseUrl}/shop/order?page=${page}&type=${type}`);
};

// 获取订单详情数据
export const getOrderAPI = function(id) {
  return request.get(`${baseUrl}/shop/order/${id}`);
};
